export function findTree(tree, fun = () => false, parent = null) {
    let temp = null
    for (const item of tree) {
        if (fun(item)) {
            temp = {data: item, parent}
            return temp
        }
        if (_isChildren(item['children'])) {
            temp = findTree(item['children'], fun, item)
            if (temp) return temp
        }
    }
    return temp;
}

export function loopTrees(tree, fun = () => false, parent = null) {
    for (const item of tree) {
        fun(item, parent)
        if (_isChildren(item['children'])) {
            loopTrees(item['children'], fun, item);
        }
    }
}

function _isChildren(children) {
    return children && children instanceof Array && children.length > 0
}
